package com.wxq.demo.controller;

import com.wxq.demo.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @GetMapping("/test")
    public void test() {
        ValueOperations<String, String> operations1 = stringRedisTemplate.opsForValue();
        operations1.set("name", "testname");
        String name = operations1.get("name");
        System.out.println(name);

        ValueOperations operations2 = redisTemplate.opsForValue();
        Book book1 = new Book();
        book1.setId(1);
        book1.setName("红楼梦");
        book1.setAuthor("曹雪芹");
        operations2.set("book", book1);
        Book book = (Book) operations2.get("book");
        System.out.println(book);
    }
}
